get Step Tracking Permission Status
Infers whether the user has granted read permission for step-count data.
Apple does not expose whether individual read permissions were granted or denied. This method works around that limitation by:
Checking whether the authorization dialog has already been shown.
If it has, querying HealthKit for step-count data over the past 7 days.
If data is returned, read permission is effectively granted.
If no data is returned, the user likely denied access (because virtually every Apple Watch generates step-count data).
when (AFHealthTracking.getStepTrackingPermissionStatus()) {
HealthPermissionStatus.LIKELY_GRANTED -> { /* show step data */}
HealthPermissionStatus.LIKELY_DENIED -> { /* prompt to enable in Health app */}
HealthPermissionStatus.NOT_DETERMINED -> { /* call requestPermissions() */}
HealthPermissionStatus.UNAVAILABLE -> { /* hide step tracking UI */}
}Content copied to clipboard